# -*- coding: utf-8 -*-

"""
Created on 2021/6/4 13:40

@File: set_Lng_and_Lat.py
@Author: LT
@Description: 在租户的界面下，把坐标给填进去；所以需要dispatcher处的列表字典更加完善一些，来填充必须的内容
"""
from requests import post
import json
import time


class SetLngLat:
    def __init__(self, userId1: '加个数字1的尾缀 是为了契合接口', station_name, latitude, longitude, address, siteId, regionCode, **kwargs):
        self.link = 'https://zhisheng.wzies.com/backend/company/site/inOrUpSite'
        self.headers = {'Content-Type': 'application/json'}  # payload形式必须有请求头表示它是什么类型的，这里用json类型！
        self.data = {
            "userId": userId1,
            "accountId": userId1,
            "site_name": station_name,
            "site_xAxis": latitude,
            "site_yAxis": longitude,
            "address": address,
            "site_id": siteId,                      # 同步之后的站点才能有
            "operation": "update",
            "province": "330000",
            "city": "330300",
            "region": regionCode,
            "timestamp": round(time.time()),
            "lang": "zh-CN"
        }
        self.res = self.__request()

    def __request(self):
        res = post(url=self.link, data=json.dumps(self.data), headers=self.headers)
        res.close()
        return res


if __name__ == '__main__':
    exp = SetLngLat(
        userId1="ZJ_016649",
        station_name="auto_bot_4（租户）",
        latitude="33",
        longitude="123",
        address="666",
        siteId="site_00009920",
        regionCode="330382"
                    )
    print(exp.res.json())
    # 返回体:
    # {'code': '1',
    # 'msg': '修改成功！',           # 缺少参数会显示-->"msg": "参数错误",
    # 'data': None,
    # 'timestamp': 1622786894}
